/** 
 * @(#)RoutingEntry.java
 */

/**
 * @author Robert Denda&Didier Gutacker
 * @version 1.1
 * @see RIPRoutingEntry
 * @see DVMRPRoutingTable 
 *
 * original author Robert Denda , changes by Didier Gutacker
 */

import java.util.Vector;

public class RoutingEntry {
  
  debug DEBUG;
 
  public int destinationID;
  public int metric;
  public Verbindung l;
  public int infinity;

  public Vector children;

  public RoutingEntry( int destinationID, int metric, Verbindung l, int infinity ) {
    this.destinationID = destinationID;
    this.metric = metric;
    this.l = l;
    this.infinity = infinity;
  } // RoutingEntry.RoutingEntry

  synchronized public boolean update( int destinationID, int metric, Verbindung l, int infinity ) {
    if ( metric == infinity  && this.l.equals( l ) ) {
      this.infinity = Math.max( this.infinity, infinity );
      this.metric = this.infinity;
      return true;
    } // if
    if ( ( metric < this.metric ) || ( ( this.metric == this.infinity ) && ( metric != infinity ) ) ){
      this.metric = metric;
      this.l = l;
      this.infinity = infinity;
      return true;
    } // if
    return false;
  } // update

  public final void addChild( Verbindung l ) {
    if ( ! l.equals( this.l ) ) {
      if ( children == null ) {
	children = new Vector();
      } // if
      if ( ! children.contains( l ) ) {
	children.addElement( l );
      } // if
    } // if
  } // RoutingEntry.addChild

  public final void removeChild( Verbindung l ) {
    if ( children != null && children.contains( l ) ) {
      children.removeElement( l );
    } // if
  } // RoutingEntry.removeChild

  public final Vector getChildList() {
    return children;
  } // RoutingEntry.getChildList

} // RoutingEntry






